<?php

namespace App\Admin\Eloquent;
use App\Exceptions\BusinessException;

class ArticleCategory extends Model
{
  /**
   * 模型使用数据库表s
   *
   * @var string
   */
  protected $table = 'article_categories';

  /**
   * 实例化模型可批量赋值
   *
   * @var array
   */
  protected $fillable = ['name', 'display', 'recommended', 'sort', 'description','parent'];

  /**
   * 属性类型转换
   *
   * @var array
   */
  protected $casts = [
    'display' => 'boolean',
    'recommended' => 'boolean',
    'sort' => 'integer'
  ];
  public function delete(){

    if($this::where('parent',$this->id)->exists()){
      throw new BusinessException("不能删除父级分类,请先删除子级分类 error-id:".$this->id);
    }

    return parent::delete();
  }
}
